home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / intrlib1.zip / WINDOW.C < prev   
C/C++ Source or Header  |  1992-03-05  |  67KB  |  1,799 lines

  1. /******************************************************************************
  2. * Iteraction library - windows.                              *
  3. *                                          *
  4. *                    Written by Gershon Elber,  Oct. 1990  *
  5. *******************************************************************************
  6. * Special notes:                                  *
  7. * The operations allowed on windows here guarantee that windows defines a     *
  8. * total order. I.e. for each two windows (even if not overlap) one can say    *
  9. * which one is above which.                              *
  10. *******************************************************************************
  11. * History:                                      *
  12. *  7 Oct 90 - Version 1.0 by Gershon Elber.                      *
  13. ******************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #ifdef __MSDOS__
  18. #include <mem.h>
  19. #include <dos.h>
  20. #endif /* __MSDOS__ */
  21. #include "intr_loc.h"
  22. #include "intr_gr.h"
  23.  
  24. #define MIN_WINDOW_SIZE  50        /* 50 by 50 is minimum size allowed. */
  25.  
  26. #define DEFAULT_FXMIN -1.0
  27. #define DEFAULT_FYMIN -1.0
  28. #define DEFAULT_FXMAX  1.0
  29. #define DEFAULT_FYMAX  1.0
  30.  
  31. #define MAP_OBJ_TO_WNDW_X(x) ((int) (DrawingWindow -> BBox._Dx * \
  32.                      (x - DrawingWindow -> FBBox.FXmin) / \
  33.                      DrawingWindow -> FBBox._FDx))
  34. #define MAP_OBJ_TO_WNDW_Y(y) ((int) (DrawingWindow -> BBox._Dy * \
  35.                      (y - DrawingWindow -> FBBox.FYmin) / \
  36.                      DrawingWindow -> FBBox._FDy))
  37.  
  38. AsyncEventStruct
  39.     _IntrAsyncLastEvent =
  40.     { ASYNC_EVNT_NONE, INTR_EVNT_NONE, NULL, 0.0, 0, 0, 0, 0 };
  41.  
  42. static int
  43.     WindowIDCounter = 1;           /* Allocate unique window I.D.'s. */
  44. static IntrRType
  45.     RealCursorX, RealCursorY;                        /* Real cursor coords. */
  46. static IntrBType
  47.     SelectAllWindows = TRUE;          /* Default - all windows are selected. */
  48. static _IntrWindowStruct
  49.     *GlblWindowsList = NULL,                 /* All windows defined. */
  50.     *DrawingWindow = NULL,     /* Window in which drawing is taking place. */
  51.     *SelectedWindow = NULL;    /* Selected window (usually where cursor is). */
  52. static IntrBBoxStruct
  53.     ResizeBBox = { 0, 0, 1000, 1000, 1000, 1000};
  54.  
  55. static void MoveWindowToTop(_IntrWindowStruct *Window);
  56. static void RedrawWindow(_IntrWindowStruct *Window);
  57. static void DrawWindowFrameAndName(_IntrWindowStruct *Window);
  58. static void DrawWindowOnePixelFrame(int Xmin, int Ymin, int Xmax, int Ymax,
  59.         IntrColorType Color, IntrIntensityType BottomRightColor,
  60.                              IntrIntensityType TopLeftColor);
  61. static void IntrWndwPutStatus(_IntrWindowStruct *Window, int Color);
  62. static void ClipPositionToResizeBBox(int *x, int *y, int Width, int Height);
  63. static void DeleteWindowFromGlblList(_IntrWindowStruct *Window);
  64. static void InsertWindowFirstGlblList(_IntrWindowStruct *Window);
  65. static void InsertWindowLastGlblList(_IntrWindowStruct *Window);
  66.  
  67. /******************************************************************************
  68. * Returns TRUE if scroll bar event had occured on the given window. Returns   *
  69. * in Value the scroll bar fraction. Should be called only from async. refresh *
  70. * functions called by WindowRefresh below.                      *
  71. ******************************************************************************/
  72. IntrBType IntrWndwIsScrollBarEvent(int WindowID, IntrBType *IsVertical,
  73.                          IntrRType *Value)
  74. {
  75.     if (_IntrAsyncLastEvent.Window != NULL &&
  76.     _IntrAsyncLastEvent.Window -> WindowID == WindowID &&
  77.         (_IntrAsyncLastEvent.AsyncEvent == ASYNC_EVNT_HSCRLBAR ||
  78.          _IntrAsyncLastEvent.AsyncEvent == ASYNC_EVNT_VSCRLBAR)) {
  79.         *Value = _IntrAsyncLastEvent.R;
  80.     *IsVertical = _IntrAsyncLastEvent.AsyncEvent == ASYNC_EVNT_VSCRLBAR;
  81.     _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_NONE;
  82.     return TRUE;
  83.     }
  84.     else
  85.     return FALSE;
  86. }
  87.  
  88. /******************************************************************************
  89. * Returns the width (in pixels) of a scroll bar.                  *
  90. ******************************************************************************/
  91. int IntrWndwScrollBarWidth(void)
  92. {
  93.     return _INTR_SCROLL_BAR_WIDTH + 2;
  94. }
  95.  
  96. /******************************************************************************
  97. * Redraw all active windows.                              *
  98. ******************************************************************************/
  99. void IntrWndwRedrawAll(void)
  100. {
  101.     _IntrWindowStruct *Window;
  102.  
  103.     IntrPushCursorType();
  104.     GRClearAllScreen();
  105.  
  106.     for (Window = GlblWindowsList;
  107.      Window != NULL;
  108.      Window = Window -> Pnext)
  109.     {
  110.     if (Window -> MappedToScreen)
  111.         RedrawWindow(Window);
  112.     }
  113.  
  114.     IntrPopCursorType();
  115. }
  116.  
  117. /******************************************************************************
  118. * Clear a window to its background color.                      *
  119. * Window is selected as new drawing window.                      *
  120. ******************************************************************************/
  121. void IntrWndwClear(int WindowID)
  122. {
  123.     _IntrWindowStruct
  124.     *Window = _IntrFindWndwUsingID(WindowID);
  125.  
  126.     _GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  127.     GRSetWriteMode(GR_COPY_PUT);
  128.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  129.  
  130.     IntrAllocColor(Window -> BackColor, INTR_INTENSITY_HIGH);
  131.     GRSBar(Window -> BBox.Xmin,
  132.        Window -> BBox.Ymin,
  133.            Window -> BBox.Xmax,
  134.        Window -> BBox.Ymax);
  135.  
  136.     DrawingWindow = Window;     /* Select this window as the drawing window. */
  137.     GRSetZoomFactor(DrawingWindow -> ZoomFactor);
  138.     GRSetPanFactors(DrawingWindow -> PanFactorX, DrawingWindow -> PanFactorY);
  139.     GRSetViewPort(DrawingWindow -> BBox.Xmin,
  140.           DrawingWindow -> BBox.Ymin,
  141.           DrawingWindow -> BBox.Xmax,
  142.           DrawingWindow -> BBox.Ymax);
  143.  
  144.     if (!IntrWndwIsAllVisible(WindowID))
  145.     MoveWindowToTop(Window);
  146. }
  147.  
  148. /******************************************************************************
  149. * Move window to top of list and clear it to its background color.          *
  150. ******************************************************************************/
  151. static void MoveWindowToTop(_IntrWindowStruct *Window)
  152. {
  153.     GRPushViewPort();
  154.     _GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  155.     IntrPushCursorType();
  156.     GRSetWriteMode(GR_COPY_PUT);
  157.  
  158.     /* Draw window frame and window name. */
  159.     DrawWindowFrameAndName(Window);
  160.  
  161.     /* If it has Pull Down menu - draw it as well. */
  162.     if (Window -> PDMenu)
  163.     _IntrPullDownMenuDrawItems(Window -> PDMenu);
  164.  
  165.     IntrAllocColor(Window -> BackColor, INTR_INTENSITY_HIGH);
  166.     GRSBar(Window -> BBox.Xmin, Window -> BBox.Ymin,
  167.            Window -> BBox.Xmax, Window -> BBox.Ymax);
  168.  
  169.     IntrPopCursorType();
  170.     GRPopViewPort();
  171. }
  172.  
  173. /******************************************************************************
  174. * Redraw the given window. Preform the following operations in the following  *
  175. * order:                                      *
  176. * 1. Draw the border with the specified color and width. If border width is   *
  177. *    zero no border is drawn. If Window has WindowName a header with this     *
  178. *    name is created as part of the border.                      *
  179. * 2. Clear the window interior to the specified back ground color.          *
  180. * 3. Call the refresh function for this window if such function is defined.   *
  181. ******************************************************************************/
  182. static void RedrawWindow(_IntrWindowStruct *Window)
  183. {
  184.     MoveWindowToTop(Window);
  185.  
  186.     /* Apply the redrawing function. */
  187.     DrawingWindow = Window;     /* Select this window as the drawing window. */
  188.     GRSetZoomFactor(DrawingWindow -> ZoomFactor);
  189.     GRSetPanFactors(DrawingWindow -> PanFactorX, DrawingWindow -> PanFactorY);
  190.     GRSetViewPort(DrawingWindow -> BBox.Xmin,
  191.           DrawingWindow -> BBox.Ymin,
  192.           DrawingWindow -> BBox.Xmax,
  193.           DrawingWindow -> BBox.Ymax);
  194.     IntrPushCursorType();
  195.     if (Window -> RefreshFunc != NULL)
  196.         (Window -> RefreshFunc)(Window -> WindowID);
  197.     IntrPopCursorType();
  198. }
  199.  
  200. /******************************************************************************
  201. * Draw the window frame. If the window has a name header associated with it,  *
  202. * it is drawn as well on the top of the window.                      *
  203. ******************************************************************************/
  204. static void DrawWindowFrameAndName(_IntrWindowStruct *Window)
  205. {
  206.     int Xmin = Window -> BBox.Xmin,
  207.         Ymin = Window -> BBox.Ymin,
  208.         Xmax = Window -> BBox.Xmax,
  209.         Ymax = Window -> BBox.Ymax,
  210.         Width = Window -> FrameWidth;
  211.     IntrBType SlctdWndw = Window == SelectedWindow || SelectAllWindows;
  212.     IntrPullDownMenuStruct *PDMenu = Window -> PDMenu;
  213.     int PDMenuHeight = PDMenu == NULL ? 0 :
  214.              IntrWndwGetHeaderHeight("M", PDMenu -> FrameWidth);
  215.  
  216.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  217.  
  218.     /* Draw the window frame. */
  219.     _IntrWndwDrawFrame(Xmin, Xmax, Ymin, Ymax, Width,
  220.                    Window -> FrameColor, FALSE,
  221.                        Window -> HScrlBarColor, Window -> HScrlBar,
  222.                        Window -> VScrlBarColor, Window -> VScrlBar,
  223.                        SlctdWndw);
  224.  
  225.     /* If window has a name associated with it draw the name on top. */
  226.     if (Window -> DrawHeader && Window -> Name != NULL) {
  227.     _IntrWndwPutNameHeader(Xmin - Window -> FrameWidth -
  228.                    (Window -> VScrlBar == INTR_SCRLBAR_LEFT
  229.                                        ? _INTR_SCROLL_BAR_WIDTH + 1 : 0),
  230.                    Xmax + Window -> FrameWidth +
  231.                                    (Window -> VScrlBar == INTR_SCRLBAR_RIGHT
  232.                                        ? _INTR_SCROLL_BAR_WIDTH + 1 : 0),
  233.                                Ymin - Window -> FrameWidth - 2 - PDMenuHeight -
  234.                                    (Window -> HScrlBar == INTR_SCRLBAR_TOP
  235.                                        ? _INTR_SCROLL_BAR_WIDTH + 1 : 0),
  236.                                Window -> FrameWidth, Window -> Name, FALSE,
  237.                                Window -> FrameColor, Window -> FrameColor,
  238.                                Window -> BackColor, SlctdWndw);
  239.         IntrWndwPutStatus(Window,
  240.               IntrAllocColor(Window -> FrameColor,
  241.                                    INTR_INTENSITY_VHIGH));
  242.     }
  243. }
  244.  
  245. /******************************************************************************
  246. * Routine to draw a window frame with the sppecified BBox and width.          *
  247. * The X/Ymin/max coordinates are of the inner (net) window.              *
  248. ******************************************************************************/
  249. void _IntrWndwDrawFrame(int Xmin, int Xmax, int Ymin, int Ymax, int Width,
  250.             IntrColorType FrameColor, IntrBType SaveUnder,
  251.                         IntrColorType HScrlBarColor, IntrScrlBarType HScrlBar,
  252.                         IntrColorType VScrlBarColor, IntrScrlBarType VScrlBar,
  253.                         IntrBType HighIntensity)
  254. {
  255.     int i,
  256.         Width4 = Width >> 2;
  257.  
  258.     Xmin -= VScrlBar == INTR_SCRLBAR_LEFT ? _INTR_SCROLL_BAR_WIDTH + 1 : 0;
  259.     Xmax += VScrlBar == INTR_SCRLBAR_RIGHT ? _INTR_SCROLL_BAR_WIDTH + 1 : 0;
  260.     Ymin -= HScrlBar == INTR_SCRLBAR_TOP ? _INTR_SCROLL_BAR_WIDTH + 1 : 0;
  261.     Ymax += HScrlBar == INTR_SCRLBAR_BOTTOM ? _INTR_SCROLL_BAR_WIDTH + 1 : 0;
  262.  
  263.     if (SaveUnder && _IntrSaveBelow)
  264.     _IntrSaveWindow(Xmin - Width, Ymin - Width,
  265.             Xmax + Width, Ymax + Width);
  266.  
  267.     /* First quarter is drawn in low color intensity. */
  268.     for (i = 1; i <= Width4; i++)
  269.     DrawWindowOnePixelFrame(Xmin - i, Ymin - i, Xmax + i, Ymax + i,
  270.                 FrameColor,
  271.                                 INTR_INTENSITY_LOW, INTR_INTENSITY_VLOW);
  272.  
  273.     /* Middle half is drawn in high color intensity. */
  274.     for (i = Width4 + 1; i <= Width - Width4; i++)
  275.     DrawWindowOnePixelFrame(Xmin - i, Ymin - i, Xmax + i, Ymax + i,
  276.                 FrameColor,
  277.                     HighIntensity ? INTR_INTENSITY_VHIGH
  278.                                            : INTR_INTENSITY_HIGH,
  279.                     HighIntensity ? INTR_INTENSITY_VHIGH
  280.                                            : INTR_INTENSITY_HIGH);
  281.  
  282.     /* Last quarter is drawn in low color intensity. */
  283.     for (i = Width - Width4 + 1; i <= Width; i++)
  284.     DrawWindowOnePixelFrame(Xmin - i, Ymin - i, Xmax + i, Ymax + i,
  285.                 FrameColor,
  286.                                 INTR_INTENSITY_VLOW, INTR_INTENSITY_LOW);
  287.  
  288.     switch (VScrlBar) {
  289.     case INTR_SCRLBAR_LEFT:
  290.         DrawWindowOnePixelFrame(Xmin, Ymin,
  291.                             Xmin + _INTR_SCROLL_BAR_WIDTH, Ymax,
  292.                     FrameColor,
  293.                         HighIntensity ? INTR_INTENSITY_VHIGH
  294.                                                : INTR_INTENSITY_HIGH,
  295.                         HighIntensity ? INTR_INTENSITY_VHIGH
  296.                                                : INTR_INTENSITY_HIGH);
  297.         IntrAllocColor(VScrlBarColor, INTR_INTENSITY_LOW);
  298.             GRSBar(Xmin + 1, Ymin + 1,
  299.                    Xmin + _INTR_SCROLL_BAR_WIDTH - 1, Ymax - 1);
  300.             break;
  301.     case INTR_SCRLBAR_RIGHT:
  302.         DrawWindowOnePixelFrame(Xmax - _INTR_SCROLL_BAR_WIDTH, Ymin,
  303.                             Xmax, Ymax,
  304.                     FrameColor,
  305.                         HighIntensity ? INTR_INTENSITY_VHIGH
  306.                                                : INTR_INTENSITY_HIGH,
  307.                         HighIntensity ? INTR_INTENSITY_VHIGH
  308.                                                : INTR_INTENSITY_HIGH);
  309.         IntrAllocColor(VScrlBarColor, INTR_INTENSITY_LOW);
  310.             GRSBar(Xmax - _INTR_SCROLL_BAR_WIDTH + 1, Ymin + 1,
  311.            Xmin - 1, Ymax - 1);
  312.             break;
  313.     }
  314.  
  315.     /* Make Xmin/max back to the real window dimenstion. */
  316.     Xmin += VScrlBar == INTR_SCRLBAR_LEFT ? _INTR_SCROLL_BAR_WIDTH + 1 : 0;
  317.     Xmax -= VScrlBar == INTR_SCRLBAR_RIGHT ? _INTR_SCROLL_BAR_WIDTH + 1 : 0;
  318.     switch (HScrlBar) {
  319.     case INTR_SCRLBAR_TOP:
  320.         DrawWindowOnePixelFrame(Xmin, Ymin,
  321.                             Xmax, Ymin + _INTR_SCROLL_BAR_WIDTH,
  322.                     FrameColor,
  323.                         HighIntensity ? INTR_INTENSITY_VHIGH
  324.                                                : INTR_INTENSITY_HIGH,
  325.                         HighIntensity ? INTR_INTENSITY_VHIGH
  326.                                                : INTR_INTENSITY_HIGH);
  327.         IntrAllocColor(HScrlBarColor, INTR_INTENSITY_LOW);
  328.             GRSBar(Xmin + 1, Ymin + 1,
  329.                    Xmax - 1, Ymin + _INTR_SCROLL_BAR_WIDTH - 1);
  330.             break;
  331.     case INTR_SCRLBAR_BOTTOM:
  332.         DrawWindowOnePixelFrame(Xmin, Ymax - _INTR_SCROLL_BAR_WIDTH,
  333.                             Xmax, Ymax,
  334.                     FrameColor,
  335.                         HighIntensity ? INTR_INTENSITY_VHIGH
  336.                                                : INTR_INTENSITY_HIGH,
  337.                         HighIntensity ? INTR_INTENSITY_VHIGH
  338.                                                : INTR_INTENSITY_HIGH);
  339.         IntrAllocColor(HScrlBarColor, INTR_INTENSITY_LOW);
  340.             GRSBar(Xmin + 1, Ymax - _INTR_SCROLL_BAR_WIDTH + 1,
  341.            Xmax - 1, Ymax - 1);
  342.             break;
  343.     }
  344. }
  345.  
  346. /****************************************************************************
  347. * Routine to update a scroll bar of a specified window.                *
  348. * RelativePosition and DisplayedFraction controls beginning of scroll bar   *
  349. * active zone and its length respectively.                    *
  350. ****************************************************************************/
  351. void IntrWndwUpdateScrollBar(int WindowID,
  352.                  IntrBType IsVertical,
  353.                      IntrRType RelativePosition,
  354.                              IntrRType DisplayedFraction)
  355. {
  356.     _IntrWindowStruct
  357.     *Window = _IntrFindWndwUsingID(WindowID);
  358.     int Xmin = Window -> BBox.Xmin,
  359.         Ymin = Window -> BBox.Ymin,
  360.         Xmax = Window -> BBox.Xmax,
  361.         Ymax = Window -> BBox.Ymax;
  362.  
  363.     if (IsVertical) {
  364.     switch (Window -> HScrlBar) {
  365.         case INTR_SCRLBAR_TOP:
  366.             Ymin -= _INTR_SCROLL_BAR_WIDTH + 1;
  367.         break;
  368.         case INTR_SCRLBAR_BOTTOM:
  369.             Ymax += _INTR_SCROLL_BAR_WIDTH + 1;
  370.         break;
  371.         }
  372.  
  373.         switch (Window -> VScrlBar) {
  374.         case INTR_SCRLBAR_LEFT:
  375.             _IntrUpdateScrollBar(Xmin - 1 - _INTR_SCROLL_BAR_WIDTH, Ymin,
  376.                              Xmin - 1, Ymax,
  377.                          RelativePosition, DisplayedFraction,
  378.                                      TRUE, Window -> VScrlBarColor);
  379.                 break;
  380.         case INTR_SCRLBAR_RIGHT:
  381.             _IntrUpdateScrollBar(Xmax + 1, Ymin,
  382.                              Xmax + 1 + _INTR_SCROLL_BAR_WIDTH, Ymax,
  383.                                        RelativePosition, DisplayedFraction,
  384.                                      TRUE, Window -> VScrlBarColor);
  385.                 break;
  386.             default:
  387.                 IntrFatalError("Window does not have a scroll bar.");
  388.         }
  389.     }
  390.     else {
  391.         switch (Window -> HScrlBar) {
  392.         case INTR_SCRLBAR_TOP:
  393.             _IntrUpdateScrollBar(Xmin, Ymin - 1 - _INTR_SCROLL_BAR_WIDTH,
  394.                              Xmax, Ymin - 1,
  395.                          RelativePosition, DisplayedFraction,
  396.                                      FALSE, Window -> HScrlBarColor);
  397.                 break;
  398.         case INTR_SCRLBAR_BOTTOM:
  399.             _IntrUpdateScrollBar(Xmin, Ymax + 1,
  400.                              Xmax, Ymax + 1 + _INTR_SCROLL_BAR_WIDTH,
  401.                                        RelativePosition, DisplayedFraction,
  402.                                      FALSE, Window -> HScrlBarColor);
  403.                 break;
  404.             default:
  405.                 IntrFatalError("Window does not have a scroll bar.");
  406.         }
  407.     }
  408. }
  409.  
  410. /****************************************************************************
  411. * Routine to draw a scroll bar in the given coordinates, given size of the  *
  412. * DisplayedFraction and the current RelativePosition.                *
  413. * View port is assumed to be the entire screen.                    *
  414. ****************************************************************************/
  415. void _IntrUpdateScrollBar(int Left,
  416.                   int Top,
  417.                   int Right,
  418.                           int Bottom,
  419.                   IntrRType RelativePosition,
  420.                           IntrRType DisplayedFraction,
  421.                           IntrBType IsVertical,
  422.                           IntrColorType ScrlBarColor)
  423. {
  424.     int ActiveMin, ActiveMax ,
  425.     Dx = Right - Left,
  426.     Dy = Bottom - Top;
  427.  
  428.     Left++;
  429.     Top++;
  430.     Right--;
  431.     Bottom--;
  432.  
  433.     GRPushViewPort();
  434.  
  435.     _GRSetViewPort(Left, Top, Right, Bottom);
  436.  
  437.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  438.     
  439.     IntrAllocColor(ScrlBarColor, INTR_INTENSITY_LOW);
  440.     GRSBar(0, 0, Right - Left, Bottom - Top);
  441.  
  442.     IntrAllocColor(ScrlBarColor, INTR_INTENSITY_VHIGH);
  443.     if (IsVertical) {
  444.         ActiveMin = ((int) (Dy * RelativePosition));
  445.         ActiveMax = ActiveMin + ((int) (Dy * DisplayedFraction));
  446.  
  447.         GRSBar(0, ActiveMin, Dx, MIN(ActiveMax, Dy - 2));
  448.     }
  449.     else {                              /* Horizontal. */
  450.         ActiveMin = ((int) (Dx * RelativePosition));
  451.         ActiveMax = ActiveMin + ((int) (Dx * DisplayedFraction));
  452.         GRSBar(ActiveMin, 0, MIN(ActiveMax, Dx - 2), Dy);
  453.     }
  454.  
  455.     GRPopViewPort();
  456. }
  457.  
  458. /******************************************************************************
  459. * Returns the expected height of the header created by _IntrWndwPutNameHeader.*
  460. ******************************************************************************/
  461. int IntrWndwGetHeaderHeight(char *Header, int FrameWidth)
  462. {
  463.     int Height;
  464.  
  465.     GRPushTextSetting();
  466.     GRSetSTextStyle(GR_FONT_DEFAULT, GR_HORIZ_DIR, GR_TEXT_MAG_1);
  467.  
  468.     Height = GRGetTextHeight(Header) + 4 + (FrameWidth << 1);
  469.  
  470.     GRPopTextSetting();
  471.  
  472.     return Height;
  473. }
  474.  
  475. /******************************************************************************
  476. * Routine to put horizontal bar with given size string and color.          *
  477. * Bar height will be string height + 4 + FrameWidth * 2 pixels.              *
  478. ******************************************************************************/
  479. void _IntrWndwPutNameHeader(int Xmin, int Xmax, int Ymax, int FrameWidth,
  480.                 char *Str, IntrBType SaveUnder,
  481.                             IntrColorType FrameColor, IntrColorType ForeColor,
  482.                             IntrColorType BackColor, IntrBType HighIntensity)
  483. {
  484.     char CpStr[80];
  485.     int i, Width, Ymin, XStr, YStr, Color,
  486.     Width4 = FrameWidth >> 2;
  487.  
  488.     GRPushTextSetting();
  489.     GRSetTextJustify(GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM);
  490.     GRSetSTextStyle(GR_FONT_DEFAULT, GR_HORIZ_DIR, GR_TEXT_MAG_1);
  491.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  492.  
  493.     strncpy(CpStr, Str, 79);
  494.  
  495.     /* Prepare some parameters and make sure string will not overflow. */
  496.     while ((Width = GRGetTextWidth(CpStr)) > Xmax - Xmin - (FrameWidth << 1) &&
  497.            Width > 0)
  498.     CpStr[strlen(CpStr) - 1] = 0;
  499.     Ymin = Ymax - IntrWndwGetHeaderHeight(CpStr, FrameWidth);
  500.  
  501.     if (SaveUnder && _IntrSaveBelow)
  502.     _IntrSaveWindow(Xmin - FrameWidth, Ymin - FrameWidth,
  503.             Xmax + FrameWidth, Ymax + FrameWidth);
  504.  
  505.     XStr = (Xmin + Xmax - Width) >> 1;
  506.     YStr = Ymax - FrameWidth - 2;
  507.  
  508.     /* First quarter is always drawn in high/low color intensity. */
  509.     for (i = 0; i < Width4; i++)
  510.     DrawWindowOnePixelFrame(Xmin + i, Ymin + i, Xmax - i, Ymax - i,
  511.                 FrameColor,
  512.                                 INTR_INTENSITY_VLOW, INTR_INTENSITY_LOW);
  513.  
  514.     /* Middle half is drawn in very high/high color intensity. */
  515.     for (i = Width4; i < FrameWidth - Width4; i++)
  516.     DrawWindowOnePixelFrame(Xmin + i, Ymin + i, Xmax - i, Ymax - i,
  517.                 FrameColor,
  518.                     HighIntensity ? INTR_INTENSITY_VHIGH
  519.                                            : INTR_INTENSITY_HIGH,
  520.                     HighIntensity ? INTR_INTENSITY_VHIGH
  521.                                            : INTR_INTENSITY_HIGH);
  522.  
  523.     /* Last quarter is always drawn in high/low color intensity. */
  524.     for (i = FrameWidth - Width4; i < FrameWidth; i++)
  525.     DrawWindowOnePixelFrame(Xmin + i, Ymin + i, Xmax - i, Ymax - i,
  526.                 FrameColor,
  527.                                 INTR_INTENSITY_LOW, INTR_INTENSITY_VLOW);
  528.  
  529.     /* Inner header is in back ground color. */
  530.     IntrAllocColor(BackColor, INTR_INTENSITY_HIGH);
  531.     GRSBar(Xmin + FrameWidth, Ymin + FrameWidth,
  532.            Xmax - FrameWidth, Ymax - FrameWidth);
  533.  
  534.     /* And finally draw the window name. */
  535.     Color = IntrAllocColor(ForeColor, INTR_INTENSITY_VHIGH);
  536.     if (strlen(CpStr) > 0) {
  537.         GRSTextShadow(XStr, YStr, Color, CpStr);
  538.     }
  539.  
  540.     GRPopTextSetting();
  541. }
  542.  
  543. /******************************************************************************
  544. * Routine to print status string on left and right of window header.          *
  545. * Note it is assumed the window HAS an header active (i.e. its name != NULL). *
  546. ******************************************************************************/
  547. static void IntrWndwPutStatus(_IntrWindowStruct *Window, int Color)
  548. {
  549.     int Xmin = Window -> BBox.Xmin,
  550.         Ymin = Window -> BBox.Ymin,
  551.         Xmax = Window -> BBox.Xmax;
  552.  
  553.     GRPushViewPort();
  554.     _GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  555.     GRPushTextSetting();
  556.     GRSetTextJustify(GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM);
  557.     GRSetSTextStyle(GR_FONT_DEFAULT, GR_HORIZ_DIR, GR_TEXT_MAG_1);
  558.  
  559.     switch (Window -> VScrlBar) {
  560.     case INTR_SCRLBAR_LEFT:
  561.         Xmin -= _INTR_SCROLL_BAR_WIDTH;
  562.         break;
  563.     case INTR_SCRLBAR_RIGHT:
  564.         Xmax += _INTR_SCROLL_BAR_WIDTH;
  565.         break;
  566.     }
  567.     switch (Window -> HScrlBar) {
  568.     case INTR_SCRLBAR_TOP:
  569.         Ymin -= _INTR_SCROLL_BAR_WIDTH;
  570.         break;
  571.     }
  572.     if (Window -> PDMenu != NULL)
  573.     Ymin -= IntrWndwGetHeaderHeight("M", Window -> PDMenu -> FrameWidth);
  574.  
  575.     if (Window -> StatusLeft) {
  576.         GRSetTextJustify(GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM);
  577.         GRSTextShadow(Xmin + 2,
  578.                   Ymin - (Window -> FrameWidth << 1) - 4,
  579.                       Color,
  580.               Window -> StatusLeft);
  581.     }
  582.     if (Window -> StatusRight != NULL) {
  583.         GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM);
  584.         GRSTextShadow(Xmax - 2,
  585.                   Ymin - (Window -> FrameWidth << 1) - 4,
  586.                       Color,
  587.               Window -> StatusRight);
  588.     }
  589.  
  590.     GRPopTextSetting();
  591.     GRPopViewPort();
  592. }
  593.  
  594. /******************************************************************************
  595. * Boolean function to determine if two given bbox domains overlap.          *
  596. ******************************************************************************/
  597. static void DrawWindowOnePixelFrame(int Xmin, int Ymin, int Xmax, int Ymax,
  598.         IntrColorType Color, IntrIntensityType BottomRightColor,
  599.                              IntrIntensityType TopLeftColor)
  600. {
  601.    IntrAllocColor(Color, BottomRightColor);
  602.    GRSMoveTo(Xmax, Ymin);
  603.    GRSLineTo(Xmax, Ymax);
  604.    GRSLineTo(Xmin, Ymax);
  605.    IntrAllocColor(Color, TopLeftColor);
  606.    GRSLineTo(Xmin, Ymin);
  607.    GRSLineTo(Xmax, Ymin);
  608. }
  609.  
  610. /******************************************************************************
  611. * Find window structure using its I.D.. Return NULL if not found.          *
  612. ******************************************************************************/
  613. _IntrWindowStruct *_IntrFindWndwUsingID(int WindowID)
  614. {
  615.     _IntrWindowStruct *Windows;
  616.  
  617.     for (Windows = GlblWindowsList;
  618.          Windows != NULL;
  619.          Windows = Windows -> Pnext) {
  620.     if (Windows -> WindowID == WindowID) return Windows;
  621.     }
  622.  
  623.     IntrFatalError("Window ID was not found.");
  624.     return NULL;
  625. }
  626.  
  627. /******************************************************************************
  628. * Function to select all windows. This mode is in fact the default and in     *
  629. * this mode ALL window's frames are drawn at maximum                  *
  630. * intensity. If FALSE only the SelectedWindow frame will be at maximum.          *
  631. ******************************************************************************/
  632. void IntrWndwSelectAll(IntrBType SelectAll)
  633. {
  634.     SelectAllWindows = SelectAll;
  635. }
  636.  
  637. /******************************************************************************
  638. * Select a window. This has the effect of making its frame intensified.       *
  639. ******************************************************************************/
  640. void IntrWndwSelect(int WindowID)
  641. {
  642.     _IntrWindowStruct
  643.     *Window = _IntrFindWndwUsingID(WindowID);
  644.  
  645.     if (Window != NULL)
  646.     SelectedWindow = Window;
  647. }
  648.  
  649. /******************************************************************************
  650. * Returns the window drawn at the given position, NULL if none.              *
  651. ******************************************************************************/
  652. _IntrWindowStruct *_IntrWndwGetWndwInPos(int x, int y)
  653. {
  654.     int Xmin, Ymin, Xmax, Ymax, FrameWidth, HeaderHeight;
  655.     _IntrWindowStruct *WndwList,
  656.         *RetWindow = NULL;
  657.  
  658.     /* Find the last window covering the given coordinates. */
  659.     for (WndwList = GlblWindowsList;
  660.          WndwList != NULL;
  661.          WndwList = WndwList->Pnext) {
  662.     if (!WndwList -> MappedToScreen) continue;
  663.     
  664.     Xmin = WndwList -> BBox.Xmin;
  665.         Ymin = WndwList -> BBox.Ymin;
  666.         Xmax = WndwList -> BBox.Xmax;
  667.         Ymax = WndwList -> BBox.Ymax;
  668.  
  669.         FrameWidth = WndwList -> FrameWidth;
  670.     HeaderHeight = IntrWndwGetHeaderHeight("M", FrameWidth);
  671.  
  672.         if (WndwList -> PDMenu != NULL) Ymin -= HeaderHeight;
  673.         if (WndwList -> DrawHeader && WndwList -> Name != NULL)
  674.         Ymin -= HeaderHeight;
  675.         switch (WndwList -> VScrlBar) {
  676.         case INTR_SCRLBAR_LEFT:
  677.         Xmin -= _INTR_SCROLL_BAR_WIDTH;
  678.         break;
  679.         case INTR_SCRLBAR_RIGHT:
  680.         Xmax += _INTR_SCROLL_BAR_WIDTH;
  681.         break;
  682.         }
  683.         switch (WndwList -> HScrlBar) {
  684.         case INTR_SCRLBAR_TOP:
  685.         Ymin -= _INTR_SCROLL_BAR_WIDTH;
  686.         break;
  687.         case INTR_SCRLBAR_BOTTOM:
  688.         Ymax += _INTR_SCROLL_BAR_WIDTH;
  689.         break;
  690.         }
  691.  
  692.         if (Xmin - FrameWidth <= x && Xmax + FrameWidth >= x &&
  693.             Ymin - FrameWidth <= y && Ymax + FrameWidth >= y)
  694.         RetWindow = WndwList;
  695.     }
  696.  
  697.     return RetWindow;
  698. }
  699.  
  700. /******************************************************************************
  701. * Test if given event should be handled internally.                  *
  702. *   The following events should be handled internally:                  *
  703. * 1. SELECT event on a visible scroll bar.                      *
  704. *    Action: RedrawWindow after updating global AsyncEvent data.          *
  705. * 2. SELECT event on a visible pull down menu.                      *
  706. *    Action: Activate pull down menu relative ActionFunc.              *
  707. * Return TRUE if Internal event had occured.                      *
  708. ******************************************************************************/
  709. IntrBType _IntrIsInternalEvent(IntrEventType Event, int x, int y)
  710. {
  711.     static _IntrWindowStruct *LastWindow;
  712.     static IntrPullDownMenuStruct
  713.         *LastPDMenu = NULL;
  714.     static int
  715.         LastIndex = -1,
  716.         ActionFuncActive = FALSE;
  717.     int Xmin, Ymin, Xmax, Ymax, FrameWidth, HeaderHeight, Index;
  718.     IntrPullDownMenuStruct *PDMenu;
  719.     _IntrWindowStruct *Window;
  720.  
  721.     /* Do not allow any internal events while something is poped up. */
  722.     if (!_IntrAllowInternalEvent()) return FALSE;
  723.  
  724.     if ((Window = _IntrWndwGetWndwInPos(x, y)) != NULL) {
  725.     Xmin = Window -> BBox.Xmin;
  726.         Ymin = Window -> BBox.Ymin;
  727.         Xmax = Window -> BBox.Xmax;
  728.         Ymax = Window -> BBox.Ymax;
  729.         FrameWidth = Window -> FrameWidth;
  730.     HeaderHeight = IntrWndwGetHeaderHeight("M", FrameWidth);
  731.  
  732.     _IntrAsyncLastEvent.Window = Window;
  733.     _IntrAsyncLastEvent.X = x;
  734.     _IntrAsyncLastEvent.Y = y;
  735.     _IntrAsyncLastEvent.IntrEvent = Event;
  736.         _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_NONE;
  737.  
  738.         if (Event == INTR_EVNT_SELECT) {
  739.             switch (Window -> HScrlBar) {
  740.             case INTR_SCRLBAR_TOP:
  741.             if (x <= Xmax && x >= Xmin &&
  742.                         y < Ymin && y >= Ymin - _INTR_SCROLL_BAR_WIDTH - 1) {
  743.                 _IntrAsyncLastEvent.R = ((IntrRType) (x - Xmin)) /
  744.                                            (Xmax - Xmin);
  745.                 _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_HSCRLBAR;
  746.                     }
  747.                 Ymin -= _INTR_SCROLL_BAR_WIDTH + 1;     /* For VScrlBar. */
  748.             break;
  749.             case INTR_SCRLBAR_BOTTOM:
  750.             if (x <= Xmax && x >= Xmin &&
  751.                         y > Ymax && y <= Ymax + _INTR_SCROLL_BAR_WIDTH + 1) {
  752.                 _IntrAsyncLastEvent.R = ((IntrRType) (x - Xmin)) /
  753.                                            (Xmax - Xmin);
  754.                 _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_HSCRLBAR;
  755.                     }
  756.             Ymax += _INTR_SCROLL_BAR_WIDTH + 1;     /* For VScrlBar. */
  757.             break;
  758.             }
  759.             switch (Window -> VScrlBar) {
  760.             case INTR_SCRLBAR_LEFT:
  761.             if (x < Xmin && x >= Xmin - _INTR_SCROLL_BAR_WIDTH - 1 &&
  762.                 y <= Ymax && y >= Ymin) {
  763.                 _IntrAsyncLastEvent.R = ((IntrRType) (y - Ymin)) /
  764.                                            (Ymax - Ymin);
  765.                 _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_VSCRLBAR;
  766.                     }
  767.             break;
  768.             case INTR_SCRLBAR_RIGHT:
  769.             if (x > Xmax && x <= Xmax + _INTR_SCROLL_BAR_WIDTH + 1 &&
  770.                 y <= Ymax && y >= Ymin) {
  771.                 _IntrAsyncLastEvent.R = ((IntrRType) (y - Ymin)) /
  772.                                            (Ymax - Ymin);
  773.                 _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_VSCRLBAR;
  774.                     }
  775.             break;
  776.             }
  777.             if (_IntrAsyncLastEvent.AsyncEvent != ASYNC_EVNT_NONE) {
  778.                 /* Move window to top (last) of list. */
  779.         DeleteWindowFromGlblList(Window);
  780.         InsertWindowLastGlblList(Window);
  781.                 RedrawWindow(Window);
  782.             _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_NONE;
  783.                 return TRUE;
  784.             }
  785.         }
  786.  
  787.         if (Window -> HScrlBar == INTR_SCRLBAR_TOP)
  788.             Ymin -= _INTR_SCROLL_BAR_WIDTH;
  789.  
  790.         Xmin -= FrameWidth;
  791.         Xmax += FrameWidth;
  792.     if (!ActionFuncActive && (PDMenu = Window -> PDMenu) != NULL) {
  793.         if (x > Xmin && x < Xmax &&
  794.                 y > Ymin - HeaderHeight - FrameWidth &&
  795.                 y < Ymin - FrameWidth &&
  796.         (Index = (x - Xmin) / PDMenu -> DrawnEntryWidth) <
  797.                                    PDMenu -> NumOfEntries) {
  798.         switch (Event) {
  799.                     case INTR_EVNT_SELECT:
  800.             _IntrAsyncLastEvent.PDBottom = Ymin - FrameWidth;
  801.             _IntrAsyncLastEvent.PDLeft = Xmin +
  802.                              PDMenu -> DrawnEntryWidth * Index;
  803.             _IntrAsyncLastEvent.AsyncEvent = ASYNC_EVNT_PDMENU;
  804.                         ActionFuncActive = TRUE;
  805.                         PDMenu -> _ActiveIndex = Index;
  806.             delay(250);           /* Make sure no events... */
  807.             IntrInputFlush();
  808.                     (PDMenu -> ActionFuncs[Index])(Index);
  809.                         PDMenu -> _ActiveIndex = -1;
  810.                         ActionFuncActive = FALSE;
  811.                         break;
  812.                     default:
  813.             if (PDMenu != LastPDMenu || Index != LastIndex) {
  814.                             if (LastPDMenu != NULL)
  815.                         _IntrPullDownInvertEntry(LastIndex, LastWindow);
  816.                     _IntrPullDownInvertEntry(Index, Window);
  817.                             LastPDMenu = PDMenu;
  818.                             LastWindow = Window;
  819.                             LastIndex = Index;
  820.                         }
  821.                         break;
  822.                 }
  823.  
  824.                 return TRUE;
  825.             }
  826.         }
  827.     }
  828.  
  829.     if (!ActionFuncActive && LastPDMenu != NULL) {
  830.     _IntrPullDownInvertEntry(LastIndex, LastWindow);
  831.         LastPDMenu = NULL;
  832.     }
  833.     return FALSE;
  834. }
  835.  
  836. /******************************************************************************
  837. * Delete a window from global window list.                      *
  838. ******************************************************************************/
  839. static void DeleteWindowFromGlblList(_IntrWindowStruct *Window)
  840. {
  841.     _IntrWindowStruct
  842.     *WindowTail = GlblWindowsList;
  843.  
  844.     if (WindowTail == NULL)
  845.     FATAL_ERROR("Window to delete not found.\n");
  846.  
  847.     if (WindowTail == Window) {
  848.     /* Its top window - make global list point on second window. */
  849.     GlblWindowsList = GlblWindowsList -> Pnext;
  850.     }
  851.     else {
  852.     /* Scan the list until the window is found. */
  853.     while (WindowTail -> Pnext != NULL) {
  854.         if (WindowTail -> Pnext == Window) break;
  855.             WindowTail = WindowTail -> Pnext;
  856.         }
  857.  
  858.         if (WindowTail -> Pnext == NULL)
  859.         FATAL_ERROR("Window to delete not found.\n");
  860.  
  861.     WindowTail -> Pnext = WindowTail -> Pnext -> Pnext;
  862.     }
  863.  
  864.     Window -> Pnext = NULL;
  865. }
  866.  
  867. /******************************************************************************
  868. * Insert a window to global window list as first.                  *
  869. * This may usually happen as a result of a window push operation.          *
  870. ******************************************************************************/
  871. static void InsertWindowFirstGlblList(_IntrWindowStruct *Window)
  872. {
  873.     if (GlblWindowsList != NULL &&
  874.     GlblWindowsList -> WindowType & INTR_WNDW_ROOT) {
  875.     /* Root window should always be left at the bottom (first). */
  876.         Window -> Pnext = GlblWindowsList -> Pnext;
  877.         GlblWindowsList -> Pnext = Window;
  878.     }
  879.     else {
  880.     Window -> Pnext = GlblWindowsList;
  881.     GlblWindowsList = Window;
  882.     }
  883. }
  884.  
  885. /******************************************************************************
  886. * Insert a window to global window list as last.                  *
  887. * This may usually happen as a result of a window pop operation.          *
  888. ******************************************************************************/
  889. static void InsertWindowLastGlblList(_IntrWindowStruct *Window)
  890. {
  891.     _IntrWindowStruct
  892.     *WindowTail = GlblWindowsList;
  893.  
  894.     if (WindowTail == NULL)
  895.     GlblWindowsList = Window;
  896.     else {
  897.         while(WindowTail -> Pnext != NULL) WindowTail = WindowTail -> Pnext;
  898.     WindowTail -> Pnext = Window;
  899.     }
  900. }
  901.  
  902. /******************************************************************************
  903. * Routine to create a new window. Note this routine does not map it onto the  *
  904. * screen (i.e. make it visible) but only defines another window.          *
  905. ******************************************************************************/
  906. int IntrWndwCreate(char *WindowName,
  907.            int FrameWidth,
  908.            IntrBBoxStruct *BBox,
  909.            IntrColorType FrameColor,
  910.            IntrColorType BackColor,
  911.            IntrCursorShapeStruct *Cursor,
  912.            IntrPullDownMenuStruct *PDMenu,
  913.            IntrIntFunc RefreshFunc)
  914. {
  915.     _IntrWindowStruct
  916.     *Window = _IntrMalloc(sizeof(_IntrWindowStruct));
  917.  
  918.     Window -> WindowID = WindowIDCounter++;
  919.     Window -> WindowType = INTR_WNDW_GRAPH;
  920.     Window -> Name = WindowName;
  921.     Window -> DrawHeader = TRUE;
  922.     Window -> WindowFullSize = FALSE;
  923.     Window -> StatusLeft = Window -> StatusRight = NULL;
  924.     Window -> MappedToScreen = FALSE;
  925.     Window -> FrameWidth = FrameWidth;
  926.     BBox -> _Dx = BBox -> Xmax - BBox -> Xmin;
  927.     BBox -> _Dy = BBox -> Ymax - BBox -> Ymin;
  928.     GEN_COPY(&Window -> BBox, BBox, sizeof(IntrBBoxStruct));
  929.     Window -> FrameColor = FrameColor;
  930.     Window -> BackColor = BackColor;
  931.     Window -> HScrlBarColor = Window -> VScrlBarColor = INTR_COLOR_RED;
  932.     Window -> HScrlBar = Window -> VScrlBar = INTR_SCRLBAR_NONE;
  933.     GEN_COPY(&Window -> Cursor, Cursor, sizeof(IntrCursorShapeStruct));
  934.     Window -> FBBox.FXmin = DEFAULT_FXMIN;
  935.     Window -> FBBox.FYmin = DEFAULT_FYMIN;
  936.     Window -> FBBox.FXmax = DEFAULT_FXMAX;
  937.     Window -> FBBox.FYmax = DEFAULT_FYMAX;
  938.     Window -> FBBox._FDx = Window -> FBBox.FXmax - Window -> FBBox.FXmin;
  939.     Window -> FBBox._FDy = Window -> FBBox.FYmax - Window -> FBBox.FYmin;
  940.     Window -> PDMenu = PDMenu;
  941.     Window -> RefreshFunc = RefreshFunc;
  942.     Window -> TextInfo = NULL;
  943.     Window -> Pnext = NULL;
  944.     Window -> ZoomFactor = 0;
  945.     Window -> PanFactorX = Window -> PanFactorY = 0;
  946.  
  947.     if (PDMenu != NULL)
  948.     PDMenu -> WindowID = Window -> WindowID;
  949.  
  950.     InsertWindowLastGlblList(Window);
  951.  
  952.     return Window -> WindowID;
  953. }
  954.  
  955. /******************************************************************************
  956. * Routine to set a window to be a root (back ground) window.              *
  957. ******************************************************************************/
  958. void IntrWndwSetRoot(int RootWindowID)
  959. {
  960.     _IntrWindowStruct
  961.     *Window = _IntrFindWndwUsingID(RootWindowID);
  962.  
  963.     IntrWndwPop(RootWindowID, TRUE, FALSE);
  964.  
  965.     Window -> WindowType |= INTR_WNDW_ROOT;
  966. }
  967.  
  968. /******************************************************************************
  969. * Routine to map window to screen if not already mapped and place it above    *
  970. * all other windows.                                  *
  971. ******************************************************************************/
  972. void IntrWndwPop(int WindowID, IntrBType DoRedraw, IntrBType DoClear)
  973. {
  974.     _IntrWindowStruct
  975.     *Window = _IntrFindWndwUsingID(WindowID);
  976.  
  977.     if (Window -> WindowType & INTR_WNDW_ROOT) return;    /* Dont pop root. */
  978.  
  979.     Window -> MappedToScreen = TRUE;
  980.     DrawingWindow = Window;
  981.     GRSetZoomFactor(DrawingWindow -> ZoomFactor);
  982.     GRSetPanFactors(DrawingWindow -> PanFactorX, DrawingWindow -> PanFactorY);
  983.     GRSetViewPort(DrawingWindow -> BBox.Xmin,
  984.           DrawingWindow -> BBox.Ymin,
  985.           DrawingWindow -> BBox.Xmax,
  986.           DrawingWindow -> BBox.Ymax);
  987.  
  988.     if (!IntrWndwIsAllVisible(WindowID)) {
  989.     if (DoRedraw)
  990.         RedrawWindow(Window);
  991.     else if (DoClear)
  992.         MoveWindowToTop(Window);
  993.     }
  994.     else {
  995.     /* Window is definitelly visible - only redraw if required. */
  996.     if (DoRedraw)
  997.         RedrawWindow(Window);
  998.     }
  999.  
  1000.     DeleteWindowFromGlblList(Window); /* Move window to top (last) of list. */
  1001.     InsertWindowLastGlblList(Window);
  1002. }
  1003.  
  1004. /******************************************************************************
  1005. * Boolean function to determine if two given bbox domains overlap.          *
  1006. ******************************************************************************/
  1007. static IntrBType WindowBBoxOverlap(IntrBBoxStruct *BBox1,
  1008.                    IntrBBoxStruct *BBox2)
  1009. {
  1010.     return !(BBox1 -> Xmax < BBox2 -> Xmin ||
  1011.          BBox1 -> Ymax < BBox2 -> Ymin ||
  1012.          BBox2 -> Xmax < BBox1 -> Xmin ||
  1013.          BBox2 -> Ymax < BBox1 -> Ymin);
  1014. }
  1015.  
  1016. /******************************************************************************
  1017. * Routine to map window to screen if not already mapped and place it below    *
  1018. * all other windows.                                  *
  1019. ******************************************************************************/
  1020. void IntrWndwPush(int WindowID, IntrBType DoRedraw)
  1021. {
  1022.     _IntrWindowStruct
  1023.     *Window = _IntrFindWndwUsingID(WindowID);
  1024.  
  1025.     if (Window -> WindowType & INTR_WNDW_ROOT) return;   /* Dont push root. */
  1026.  
  1027.     if (!Window -> MappedToScreen) Window -> MappedToScreen = TRUE;
  1028.  
  1029.     DeleteWindowFromGlblList(Window);   /* Move wndw to list bottom (first). */
  1030.     InsertWindowFirstGlblList(Window);
  1031.  
  1032.     if (DoRedraw)
  1033.     IntrWndwRedrawAll();                  /* Update all windows. */
  1034. }
  1035.  
  1036. /******************************************************************************
  1037. * Routine to map window to screen if not already mapped and place it below    *
  1038. * all other windows.                                  *
  1039. ******************************************************************************/
  1040. IntrBType IntrWndwIsAllVisible(int WindowID)
  1041. {
  1042.     _IntrWindowStruct *W,
  1043.     *Window = _IntrFindWndwUsingID(WindowID);
  1044.  
  1045.     if (!Window -> MappedToScreen) return FALSE;
  1046.  
  1047.     for (W = Window -> Pnext; W != NULL; W = W -> Pnext)
  1048.     if (WindowBBoxOverlap(&Window -> BBox, &W -> BBox)) return FALSE;
  1049.  
  1050.     return TRUE;
  1051. }
  1052.  
  1053. /******************************************************************************
  1054. * Routine to set a bound on window move/resize operations.              *
  1055. ******************************************************************************/
  1056. void IntrWndwSetResizeBBox(IntrBBoxStruct *BBox)
  1057. {
  1058.     GEN_COPY(&ResizeBBox, BBox, sizeof(IntrBBoxStruct));
  1059.  
  1060.     ResizeBBox._Dx = ResizeBBox.Xmax - ResizeBBox.Xmin;
  1061.     ResizeBBox._Dy = ResizeBBox.Ymax - ResizeBBox.Ymin;
  1062. }
  1063.  
  1064. /******************************************************************************
  1065. * Select a window by picking a point on it.                      *
  1066. ******************************************************************************/
  1067. int IntrWndwPick(void)
  1068. {
  1069.     int x, y;
  1070.     _IntrWindowStruct *Window;
  1071.     IntrCursorShapeStruct Cursor;
  1072.     IntrEventType Event;
  1073.  
  1074.     Cursor.CursorType = INTR_CURSOR_ARROW;
  1075.     IntrDrawMessage("Select window", INTR_COLOR_YELLOW, INTR_COLOR_YELLOW);
  1076.  
  1077.     IntrPushCursorType();
  1078.     IntrSetCursorType(&Cursor);
  1079.  
  1080.     do {
  1081.         Event = IntrGetEventWait(&x, &y);
  1082.     ClipPositionToResizeBBox(&x, &y, 0, 0);
  1083.     }
  1084.     while (Event != INTR_EVNT_SELECT && Event != INTR_EVNT_ABORT);
  1085.  
  1086.     IntrPopCursorType();
  1087.  
  1088.     IntrEraseMessage();
  1089.  
  1090.     if (Event == INTR_EVNT_ABORT) return FALSE;
  1091.  
  1092.     Window = _IntrWndwGetWndwInPos(x, y);
  1093.  
  1094.     if (Window != NULL)
  1095.     return Window -> WindowID;
  1096.     else
  1097.         return -1;
  1098. }
  1099.  
  1100. /******************************************************************************
  1101. * Clip given coordinates to resize bounding box and update GRCurrentCursorX/Y *
  1102. * if necessary.                                      *
  1103. ******************************************************************************/
  1104. static void ClipPositionToResizeBBox(int *x, int *y, int Width, int Height)
  1105. {
  1106.     if (ResizeBBox.Xmin > *x - Width)
  1107.     GRCurrentCursorX = *x = ResizeBBox.Xmin + Width;
  1108.     if (ResizeBBox.Xmax < *x + Width)
  1109.         GRCurrentCursorX = *x = ResizeBBox.Xmax - Width;
  1110.     if (ResizeBBox.Ymin > *y - Height)
  1111.     GRCurrentCursorY = *y = ResizeBBox.Ymin + Height;
  1112.     if (ResizeBBox.Ymax < *y + Height)
  1113.         GRCurrentCursorY = *y = ResizeBBox.Ymax - Height;
  1114. }
  1115.  
  1116. /******************************************************************************
  1117. * Routine to resize a window. Returns TRUE if window has been modified.          *
  1118. ******************************************************************************/
  1119. IntrBType IntrWndwResize(int WindowID, IntrBType Refresh)
  1120. {
  1121.     int x, y;
  1122.     char Str[80];
  1123.     IntrEventType Event;
  1124.     IntrCursorShapeStruct Cursor;
  1125.     _IntrWindowStruct
  1126.     *Window = _IntrFindWndwUsingID(WindowID);
  1127.     IntrBBoxStruct
  1128.         *BBox = &Window -> BBox;
  1129.     int Xmin = BBox -> Xmin,
  1130.     Ymin = BBox -> Ymin,
  1131.         Xmax = BBox -> Xmax,
  1132.         Ymax = BBox -> Ymax;
  1133.  
  1134.     if (Refresh) MoveWindowToTop(Window);
  1135.  
  1136.     /* Pick the corner of the window to move. */
  1137.     if (Window -> Name != NULL) {
  1138.     sprintf(Str, "Select first \"%s\" corner", Window -> Name);
  1139.         IntrDrawMessage(Str, INTR_COLOR_YELLOW, INTR_COLOR_YELLOW);
  1140.     }
  1141.     else
  1142.         IntrDrawMessage("Select first window corner", INTR_COLOR_YELLOW,
  1143.                                   INTR_COLOR_YELLOW);
  1144.     Cursor.CursorType = INTR_CURSOR_ARROW;
  1145.     IntrPushCursorType();
  1146.     IntrSetCursorType(&Cursor);
  1147.     GRCurrentCursorX = (Xmin + Xmax) >> 1;
  1148.     GRCurrentCursorY = (Ymin + Ymax) >> 1;
  1149.     do {
  1150.         Event = IntrGetEventWait(&x, &y);
  1151.     ClipPositionToResizeBBox(&x, &y, 0, 0);
  1152.     }
  1153.     while (Event != INTR_EVNT_SELECT && Event != INTR_EVNT_ABORT);
  1154.     IntrEraseMessage();
  1155.     IntrPopCursorType();
  1156.     if (Event == INTR_EVNT_ABORT) {
  1157.     if (Refresh) IntrWndwRedrawAll();
  1158.         return FALSE;
  1159.     }
  1160.  
  1161.     IntrDrawMessage("Select second corner position", INTR_COLOR_YELLOW,
  1162.                                  INTR_COLOR_YELLOW);
  1163.     BBox -> Xmin = Cursor.LastX = GRCurrentCursorX = x;
  1164.     BBox -> Ymin = Cursor.LastY = GRCurrentCursorY = y;
  1165.     IntrPushCursorType();
  1166.     Cursor.CursorType = INTR_CURSOR_BOX_LAST;
  1167.     Cursor.LastHV = TRUE;
  1168.     IntrSetCursorType(&Cursor);
  1169.     do {
  1170.         Event = IntrGetEventWait(&x, &y);
  1171.     ClipPositionToResizeBBox(&x, &y, 0, 0);
  1172.     }
  1173.     while (Event != INTR_EVNT_SELECT && Event != INTR_EVNT_ABORT);
  1174.     IntrPopCursorType();
  1175.     IntrEraseMessage();
  1176.     if (Event == INTR_EVNT_ABORT) {
  1177.     if (Refresh) IntrWndwRedrawAll();
  1178.         return FALSE;
  1179.     }
  1180.  
  1181.     BBox -> Xmax = x;
  1182.     BBox -> Ymax = y;
  1183.     if (BBox -> Xmax < BBox -> Xmin)
  1184.     SWAP(BBox -> Xmax, BBox -> Xmin, int);
  1185.     if (BBox -> Ymax < BBox -> Ymin)
  1186.     SWAP(BBox -> Ymax, BBox -> Ymin, int);
  1187.  
  1188.     /* Make sure window is not too small. */
  1189.     if (BBox -> Xmax - BBox -> Xmin < MIN_WINDOW_SIZE)
  1190.     BBox -> Xmax = BBox -> Xmin + MIN_WINDOW_SIZE;
  1191.     if (BBox -> Ymax - BBox -> Ymin < MIN_WINDOW_SIZE)
  1192.     BBox -> Ymax = BBox -> Ymin + MIN_WINDOW_SIZE;
  1193.  
  1194.     BBox -> _Dx = BBox -> Xmax - BBox -> Xmin;
  1195.     BBox -> _Dy = BBox -> Ymax - BBox -> Ymin;
  1196.  
  1197.     if (Refresh) IntrWndwRedrawAll();
  1198.  
  1199.     return TRUE;
  1200. }
  1201.  
  1202. /******************************************************************************
  1203. * Routine to zoom/unzoom a window to/from full size from/to current size.     *
  1204. * It is assumed the full size specification is saved in ResizeBBox.          *
  1205. ******************************************************************************/
  1206. void IntrWndwFullSize(int WindowID, IntrBType Refresh)
  1207. {
  1208.     _IntrWindowStruct
  1209.     *Window = _IntrFindWndwUsingID(WindowID);
  1210.     IntrBBoxStruct
  1211.     *BBox = &Window -> BBox;
  1212.  
  1213.     if (Window -> WindowFullSize) {
  1214.     GEN_COPY(&Window -> BBox, &Window -> PushBBox, sizeof(IntrBBoxStruct));
  1215.     Window -> WindowFullSize = FALSE;
  1216.  
  1217.     if (Refresh) IntrWndwRedrawAll();
  1218.     }
  1219.     else {
  1220.     GEN_COPY(&Window -> PushBBox, &Window -> BBox, sizeof(IntrBBoxStruct));
  1221.     GEN_COPY(BBox, &ResizeBBox, sizeof(IntrBBoxStruct));
  1222.     Window -> WindowFullSize = TRUE;
  1223.  
  1224.     if (Refresh) RedrawWindow(Window);
  1225.     }
  1226. }
  1227.  
  1228. /******************************************************************************
  1229. * Routine to move a window. Returns TRUE if window has been modified.          *
  1230. ******************************************************************************/
  1231. IntrBType IntrWndwMove(int WindowID, IntrBType Refresh)
  1232. {
  1233.     int x, y;
  1234.     IntrEventType Event;
  1235.     IntrCursorShapeStruct Cursor;
  1236.     _IntrWindowStruct
  1237.     *Window = _IntrFindWndwUsingID(WindowID);
  1238.     IntrBBoxStruct
  1239.         *BBox = &Window -> BBox;
  1240.     int Xmin = BBox -> Xmin,
  1241.         Ymin = BBox -> Ymin,
  1242.         Xmax = BBox -> Xmax,
  1243.         Ymax = BBox -> Ymax;
  1244.  
  1245.     if (Refresh) MoveWindowToTop(Window);
  1246.  
  1247.     /* Pick the new position of the window. */
  1248.     IntrPushCursorType();
  1249.     Cursor.CursorType = INTR_CURSOR_BOX;
  1250.     Cursor.Width = (Xmax - Xmin) >> 1;
  1251.     Cursor.Height = (Ymax - Ymin) >> 1;
  1252.     IntrSetCursorType(&Cursor);
  1253.     GRCurrentCursorX = (Xmin + Xmax) >> 1;
  1254.     GRCurrentCursorY = (Ymin + Ymax) >> 1;
  1255.  
  1256.     IntrDrawMessage("Select new window position", INTR_COLOR_YELLOW,
  1257.                               INTR_COLOR_YELLOW);
  1258.  
  1259.     do {
  1260.         Event = IntrGetEventWait(&x, &y);
  1261.     ClipPositionToResizeBBox(&x, &y, Cursor.Width, Cursor.Height);
  1262.     }
  1263.     while (Event != INTR_EVNT_SELECT && Event != INTR_EVNT_ABORT);
  1264.  
  1265.     IntrEraseMessage();
  1266.     IntrPopCursorType();
  1267.  
  1268.     if (Event == INTR_EVNT_SELECT) {
  1269.     BBox -> Xmin = x - Cursor.Width;
  1270.     BBox -> Ymin = y - Cursor.Height;
  1271.         BBox -> Xmax = BBox -> Xmin + BBox -> _Dx;
  1272.         BBox -> Ymax = BBox -> Ymin + BBox -> _Dy;
  1273.  
  1274.     if (Refresh) IntrWndwRedrawAll();
  1275.  
  1276.         return TRUE;
  1277.     }
  1278.     else {
  1279.     if (Refresh) IntrWndwRedrawAll();
  1280.  
  1281.     return FALSE;
  1282.     }
  1283. }
  1284.  
  1285. /******************************************************************************
  1286. * Routine to hide a window - unmap it from screen.                  *
  1287. *   If Refresh then screen is updated on this hidden window.              *
  1288. ******************************************************************************/
  1289. void IntrWndwHide(int WindowID, IntrBType Refresh)
  1290. {
  1291.     _IntrWindowStruct
  1292.     *Window = _IntrFindWndwUsingID(WindowID);
  1293.  
  1294.     if (Window -> MappedToScreen) {
  1295.         Window -> MappedToScreen = FALSE;
  1296.  
  1297.         if (Refresh) IntrWndwRedrawAll();
  1298.     }
  1299. }
  1300.  
  1301. /******************************************************************************
  1302. * Routine to delete a window.                              *
  1303. *   If Refresh then screen is updated on this hidden window.              *
  1304. ******************************************************************************/
  1305. void IntrWndwDelete(int WindowID, IntrBType Refresh)
  1306. {
  1307.     _IntrWindowStruct
  1308.     *Window = _IntrFindWndwUsingID(WindowID);
  1309.  
  1310.     IntrWndwHide(WindowID, Refresh);
  1311.  
  1312.     DeleteWindowFromGlblList(Window);
  1313.     if (Window -> TextInfo != NULL)
  1314.     _IntrTextWndwDelete(Window -> TextInfo);
  1315.     if (Window -> PDMenu != NULL)
  1316.     IntrPullDownMenuDelete(Window -> PDMenu);
  1317.     _IntrFree(Window);
  1318. }
  1319.  
  1320. /******************************************************************************
  1321. * Routine to return window bounding box.                      *
  1322. ******************************************************************************/
  1323. IntrBBoxStruct *IntrWndwGetBBox(int WindowID)
  1324. {
  1325.     _IntrWindowStruct
  1326.     *Window = _IntrFindWndwUsingID(WindowID);
  1327.  
  1328.     return &Window -> BBox;
  1329. }
  1330.  
  1331. /******************************************************************************
  1332. * Routine to return window float bounding box.                      *
  1333. ******************************************************************************/
  1334. IntrFBBoxStruct *IntrWndwGetFBBox(int WindowID)
  1335. {
  1336.     _IntrWindowStruct
  1337.     *Window = _IntrFindWndwUsingID(WindowID);
  1338.  
  1339.     return &Window -> FBBox;
  1340. }
  1341.  
  1342. /******************************************************************************
  1343. * Routine to return window border color.                      *
  1344. ******************************************************************************/
  1345. IntrColorType IntrWndwGetFrameColor(int WindowID)
  1346. {
  1347.     _IntrWindowStruct
  1348.     *Window = _IntrFindWndwUsingID(WindowID);
  1349.  
  1350.     return Window -> FrameColor;
  1351. }
  1352.  
  1353. /******************************************************************************
  1354. * Routine to return window back ground color.                      *
  1355. ******************************************************************************/
  1356. IntrColorType IntrWndwGetBackGroundColor(int WindowID)
  1357. {
  1358.     _IntrWindowStruct
  1359.     *Window = _IntrFindWndwUsingID(WindowID);
  1360.  
  1361.     return Window -> BackColor;
  1362. }
  1363.  
  1364. /******************************************************************************
  1365. * Routine to return window cursor shape.                      *
  1366. ******************************************************************************/
  1367. IntrCursorShapeStruct *IntrWndwGetCursorShape(int WindowID)
  1368. {
  1369.     _IntrWindowStruct
  1370.     *Window = _IntrFindWndwUsingID(WindowID);
  1371.  
  1372.     return &Window -> Cursor;
  1373. }
  1374.  
  1375. /******************************************************************************
  1376. * Routine to return the pull down menu of the window (if any).              *
  1377. ******************************************************************************/
  1378. IntrPullDownMenuStruct *IntrWndwGetPullDownMenu(int WindowID)
  1379. {
  1380.     _IntrWindowStruct
  1381.     *Window = _IntrFindWndwUsingID(WindowID);
  1382.  
  1383.     return Window -> PDMenu;
  1384. }
  1385.  
  1386. /******************************************************************************
  1387. * Routine to return the zoom factor drawing of the window.              *
  1388. ******************************************************************************/
  1389. int IntrWndwGetZoomFactor(int WindowID)
  1390. {
  1391.     _IntrWindowStruct
  1392.     *Window = _IntrFindWndwUsingID(WindowID);
  1393.  
  1394.     return Window -> ZoomFactor;
  1395. }
  1396.  
  1397. /******************************************************************************
  1398. * Routine to get window refresh function.                      *
  1399. ******************************************************************************/
  1400. IntrIntFunc IntrWndwGetRefreshFunc(int WindowID)
  1401. {
  1402.     _IntrWindowStruct
  1403.     *Window = _IntrFindWndwUsingID(WindowID);
  1404.  
  1405.     return Window -> RefreshFunc;
  1406. }
  1407.  
  1408. /******************************************************************************
  1409. * Routine to return the panning values for drawing in the window.          *
  1410. ******************************************************************************/
  1411. void IntrWndwGetPanFactors(int WindowID, int *x, int *y)
  1412. {
  1413.     _IntrWindowStruct
  1414.     *Window = _IntrFindWndwUsingID(WindowID);
  1415.  
  1416.     *x = Window -> PanFactorX;
  1417.     *y = Window -> PanFactorY;
  1418. }
  1419.  
  1420. /******************************************************************************
  1421. * Routine to set window Name.                              *
  1422. ******************************************************************************/
  1423. void IntrWndwSetName(int WindowID, char *Name)
  1424. {
  1425.     _IntrWindowStruct
  1426.     *Window = _IntrFindWndwUsingID(WindowID);
  1427.  
  1428.     Window -> Name = Name;
  1429. }
  1430.  
  1431. /******************************************************************************
  1432. * Routine to set the display of a window header (also requires Name slot)     *
  1433. ******************************************************************************/
  1434. void IntrWndwSetDrawHeader(int WindowID, IntrBType DrawHeader)
  1435. {
  1436.     _IntrWindowStruct
  1437.     *Window = _IntrFindWndwUsingID(WindowID);
  1438.  
  1439.     Window -> DrawHeader = DrawHeader;
  1440. }
  1441.  
  1442. /******************************************************************************
  1443. * Routine to set window BBox - practically resize/move the window.          *
  1444. ******************************************************************************/
  1445. void IntrWndwSetBBox(int WindowID, IntrBBoxStruct *BBox)
  1446. {
  1447.     _IntrWindowStruct
  1448.     *Window = _IntrFindWndwUsingID(WindowID);
  1449.  
  1450.     BBox -> _Dx = BBox -> Xmax - BBox -> Xmin;
  1451.     BBox -> _Dy = BBox -> Ymax - BBox -> Ymin;
  1452.  
  1453.     GEN_COPY(&Window -> BBox, BBox, sizeof(IntrBBoxStruct));
  1454. }
  1455.  
  1456. /******************************************************************************
  1457. * Routine to set window FBBox - practically translate/scale floating drawing. *
  1458. ******************************************************************************/
  1459. void IntrWndwSetFBBox(int WindowID, IntrFBBoxStruct *FBBox)
  1460. {
  1461.     _IntrWindowStruct
  1462.     *Window = _IntrFindWndwUsingID(WindowID);
  1463.  
  1464.     FBBox -> _FDx = FBBox -> FXmax - FBBox -> FXmin;
  1465.     FBBox -> _FDy = FBBox -> FYmax - FBBox -> FYmin;
  1466.  
  1467.     GEN_COPY(&Window -> FBBox, FBBox, sizeof(IntrFBBoxStruct));
  1468. }
  1469.  
  1470. /******************************************************************************
  1471. * Routine to set window border color.                          *
  1472. ******************************************************************************/
  1473. void IntrWndwSetFrameColor(int WindowID, IntrColorType FrameColor)
  1474. {
  1475.     _IntrWindowStruct
  1476.     *Window = _IntrFindWndwUsingID(WindowID);
  1477.  
  1478.     Window -> FrameColor = FrameColor;
  1479. }
  1480.  
  1481. /******************************************************************************
  1482. * Routine to set window back ground color.                      *
  1483. ******************************************************************************/
  1484. void IntrWndwSetBackGroundColor(int WindowID, IntrColorType BackColor)
  1485. {
  1486.     _IntrWindowStruct
  1487.     *Window = _IntrFindWndwUsingID(WindowID);
  1488.  
  1489.     Window -> BackColor = BackColor;
  1490. }
  1491.  
  1492. /******************************************************************************
  1493. * Routine to set window scroll bar.                          *
  1494. ******************************************************************************/
  1495. void IntrWndwSetScrlBar(int WindowID,
  1496.             IntrBType IsVertical,
  1497.             IntrScrlBarType ScrlBar,
  1498.                         IntrColorType ScrlBarColor)
  1499. {
  1500.     _IntrWindowStruct
  1501.     *Window = _IntrFindWndwUsingID(WindowID);
  1502.  
  1503.     if (IsVertical) {
  1504.     Window -> VScrlBar = ScrlBar;
  1505.     Window -> VScrlBarColor = ScrlBarColor;
  1506.     }
  1507.     else {
  1508.     Window -> HScrlBar = ScrlBar;
  1509.     Window -> HScrlBarColor = ScrlBarColor;
  1510.     }
  1511. }
  1512.  
  1513. /******************************************************************************
  1514. * Routine to set window cursor shape.                          *
  1515. ******************************************************************************/
  1516. void IntrWndwSetCursorShape(int WindowID, IntrCursorShapeStruct *Cursor)
  1517. {
  1518.     _IntrWindowStruct
  1519.     *Window = _IntrFindWndwUsingID(WindowID);
  1520.  
  1521.     GEN_COPY(&Window -> Cursor, Cursor, sizeof(IntrCursorShapeStruct));
  1522. }
  1523.  
  1524. /******************************************************************************
  1525. * Routine to set window pull down menu.                          *
  1526. ******************************************************************************/
  1527. void IntrWndwSetPullDownMenu(int WindowID, IntrPullDownMenuStruct *PDMenu)
  1528. {
  1529.     _IntrWindowStruct
  1530.     *Window = _IntrFindWndwUsingID(WindowID);
  1531.  
  1532.     if (Window -> PDMenu)
  1533.     IntrPullDownMenuDelete(Window -> PDMenu);
  1534.     Window -> PDMenu = PDMenu;
  1535. }
  1536.  
  1537. /******************************************************************************
  1538. * Routine to set window refresh function.                      *
  1539. ******************************************************************************/
  1540. void IntrWndwSetRefreshFunc(int WindowID, IntrIntFunc RefreshFunc)
  1541. {
  1542.     _IntrWindowStruct
  1543.     *Window = _IntrFindWndwUsingID(WindowID);
  1544.  
  1545.     Window -> RefreshFunc = RefreshFunc;
  1546. }
  1547.  
  1548. /******************************************************************************
  1549. * Routine to update panning values of drawings in window.              *
  1550. ******************************************************************************/
  1551. void IntrWndwUpdatePanning(int WindowID, int x, int y)
  1552. {
  1553.     _IntrWindowStruct
  1554.     *Window = _IntrFindWndwUsingID(WindowID);
  1555.  
  1556.     Window -> PanFactorX += x;
  1557.     Window -> PanFactorY += y;
  1558. }
  1559.  
  1560. /******************************************************************************
  1561. * Routine to set panning values of drawings in window.                  *
  1562. ******************************************************************************/
  1563. void IntrWndwSetPanning(int WindowID, int x, int y)
  1564. {
  1565.     _IntrWindowStruct
  1566.     *Window = _IntrFindWndwUsingID(WindowID);
  1567.  
  1568.     Window -> PanFactorX = x;
  1569.     Window -> PanFactorY = y;
  1570. }
  1571.  
  1572. /******************************************************************************
  1573. * Routine to update zoom value of drawings in window.                  *
  1574. ******************************************************************************/
  1575. void IntrWndwUpdateZoom(int WindowID, int Zoom)
  1576. {
  1577.     _IntrWindowStruct
  1578.     *Window = _IntrFindWndwUsingID(WindowID);
  1579.  
  1580.     Window -> ZoomFactor += Zoom;
  1581. }
  1582.  
  1583. /******************************************************************************
  1584. * Routine to update zoom value of drawings in window.                  *
  1585. ******************************************************************************/
  1586. void IntrWndwSetZoom(int WindowID, int Zoom)
  1587. {
  1588.     _IntrWindowStruct
  1589.     *Window = _IntrFindWndwUsingID(WindowID);
  1590.  
  1591.     Window -> ZoomFactor = Zoom;
  1592. }
  1593.  
  1594. /******************************************************************************
  1595. * Routine to set status string on left and right of window header.          *
  1596. ******************************************************************************/
  1597. void IntrWndwSetStatus(int WindowID, char *StatusLeft, char *StatusRight,
  1598.                                 IntrBType Refresh)
  1599. {
  1600.     _IntrWindowStruct
  1601.     *Window = _IntrFindWndwUsingID(WindowID);
  1602.  
  1603.     if (Refresh && Window -> Name && Window -> MappedToScreen) {
  1604.     /* If this window is not the top one - pop it up. */
  1605.     if (Window -> Pnext != NULL)
  1606.         IntrWndwPop(WindowID, TRUE, FALSE);
  1607.  
  1608.         IntrWndwPutStatus(Window,
  1609.                   IntrAllocColor(Window -> BackColor,
  1610.                                        INTR_INTENSITY_HIGH));
  1611.     }
  1612.  
  1613.     if (Window -> StatusLeft)
  1614.     _IntrFree(Window -> StatusLeft);
  1615.     if (Window -> StatusRight)
  1616.     _IntrFree(Window -> StatusRight);
  1617.     Window -> StatusLeft = strdup(StatusLeft);
  1618.     Window -> StatusRight = strdup(StatusRight);
  1619.  
  1620.     if (Refresh && Window -> Name && Window -> MappedToScreen)
  1621.         IntrWndwPutStatus(Window,
  1622.                   IntrAllocColor(Window -> FrameColor,
  1623.                                        INTR_INTENSITY_VHIGH));
  1624. }
  1625.  
  1626. /******************************************************************************
  1627. * Line in window space.                                  *
  1628. ******************************************************************************/
  1629. void IntrWndwILine(int x1, int y1, int x2, int y2)
  1630. {
  1631.     GRSLine(x1, y1, x2, y2);
  1632. }
  1633.  
  1634. /******************************************************************************
  1635. * Line in object space.                                  *
  1636. ******************************************************************************/
  1637. void IntrWndwRLine(IntrRType x1, IntrRType y1, IntrRType x2, IntrRType y2)
  1638. {
  1639.     IntrWndwRMoveTo(x1, y1);
  1640.     IntrWndwRLineTo(x2, y2);
  1641. }
  1642.  
  1643. /******************************************************************************
  1644. * MoveTo in window space.                              *
  1645. ******************************************************************************/
  1646. void IntrWndwIMoveTo(int x, int y)
  1647. {
  1648.     GRSMoveTo(x, y);
  1649. }
  1650.  
  1651. /******************************************************************************
  1652. * MoveTo in object space.                              *
  1653. ******************************************************************************/
  1654. void IntrWndwRMoveTo(IntrRType x, IntrRType y)
  1655. {
  1656.     GRSMoveTo(MAP_OBJ_TO_WNDW_X(RealCursorX = x),
  1657.           MAP_OBJ_TO_WNDW_Y(RealCursorY = y));
  1658. }
  1659.  
  1660. /******************************************************************************
  1661. * LineTo in window space.                              *
  1662. ******************************************************************************/
  1663. void IntrWndwILineTo(int x, int y)
  1664. {
  1665.     GRSLineTo(x, y);
  1666. }
  1667.  
  1668. /******************************************************************************
  1669. * LineTo in object space.                              *
  1670. ******************************************************************************/
  1671. void IntrWndwRLineTo(IntrRType x, IntrRType y)
  1672. {
  1673.     GRSLineTo(MAP_OBJ_TO_WNDW_X(RealCursorX = x),
  1674.           MAP_OBJ_TO_WNDW_Y(RealCursorY = y));
  1675. }
  1676.  
  1677.  
  1678. /******************************************************************************
  1679. * MoveRel in window space.                              *
  1680. ******************************************************************************/
  1681. void IntrWndwIMoveRel(int x, int y)
  1682. {
  1683.     GRSMoveRel(x, y);
  1684. }
  1685.  
  1686. /******************************************************************************
  1687. * MoveRel in object space (not sure what it actually means).              *
  1688. ******************************************************************************/
  1689. void IntrWndwRMoveRel(IntrRType x, IntrRType y)
  1690. {
  1691.     GRSMoveRel(MAP_OBJ_TO_WNDW_X(x) - MAP_OBJ_TO_WNDW_X(RealCursorX),
  1692.            MAP_OBJ_TO_WNDW_Y(y) - MAP_OBJ_TO_WNDW_X(RealCursorY));
  1693.  
  1694.     RealCursorX = x;
  1695.     RealCursorY = y;
  1696. }
  1697.  
  1698. /******************************************************************************
  1699. * LineRel in window space.                              *
  1700. ******************************************************************************/
  1701. void IntrWndwILineRel(int x, int y)
  1702. {
  1703.     GRSLineRel(x, y);
  1704. }
  1705.  
  1706. /******************************************************************************
  1707. * LineRel in object space (not sure what it actually means).              *
  1708. ******************************************************************************/
  1709. void IntrWndwRLineRel(IntrRType x, IntrRType y)
  1710. {
  1711.     GRSLineRel(MAP_OBJ_TO_WNDW_X(x) - MAP_OBJ_TO_WNDW_X(RealCursorX),
  1712.            MAP_OBJ_TO_WNDW_Y(y) - MAP_OBJ_TO_WNDW_X(RealCursorY));
  1713.  
  1714.     RealCursorX = x;
  1715.     RealCursorY = y;
  1716. }
  1717.  
  1718. /******************************************************************************
  1719. * Poly in window space.                                  *
  1720. ******************************************************************************/
  1721. void IntrWndwIPoly(int n, int *Points, int Fill)
  1722. {
  1723.     GRPoly(n, Points, Fill);
  1724. }
  1725.  
  1726. /******************************************************************************
  1727. * Bar in window space.                                  *
  1728. ******************************************************************************/
  1729. void IntrWndwIBar(int x1, int y1, int x2, int y2)
  1730. {
  1731.     GRBar(x1, y1, x2, y2);
  1732. }
  1733.  
  1734. /******************************************************************************
  1735. * Bar in object space.                                  *
  1736. ******************************************************************************/
  1737. void IntrWndwRBar(IntrRType x1,
  1738.           IntrRType y1,
  1739.           IntrRType x2,
  1740.           IntrRType y2)
  1741. {
  1742.     GRBar(MAP_OBJ_TO_WNDW_X(x1), MAP_OBJ_TO_WNDW_Y(y1),
  1743.       MAP_OBJ_TO_WNDW_X(x2), MAP_OBJ_TO_WNDW_Y(y2));
  1744. }
  1745.  
  1746. /******************************************************************************
  1747. * Circle in window space.                              *
  1748. ******************************************************************************/
  1749. void IntrWndwICircle(int x, int y, int r)
  1750. {
  1751.     GRCircle(x, y, r);
  1752. }
  1753.  
  1754. /******************************************************************************
  1755. * Circle in object space.                              *
  1756. ******************************************************************************/
  1757. void IntrWndwRCircle(IntrRType x, IntrRType y, IntrRType r)
  1758. {
  1759.     GRCircle(MAP_OBJ_TO_WNDW_X(x), MAP_OBJ_TO_WNDW_Y(y),
  1760.                       (int) (DrawingWindow -> BBox._Dx * r));
  1761. }
  1762.  
  1763. /******************************************************************************
  1764. * Arc in window space.                                  *
  1765. ******************************************************************************/
  1766. void IntrWndwIArc(int x, int y, int StAngle, int EndAngle, int r)
  1767. {
  1768.     GRArc(x, y, StAngle, EndAngle, r);
  1769. }
  1770.  
  1771. /******************************************************************************
  1772. * Arc in object space.                                  *
  1773. ******************************************************************************/
  1774. void IntrWndwRArc(IntrRType x,
  1775.           IntrRType y,
  1776.           int StAngle,
  1777.           int EndAngle,
  1778.           IntrRType r)
  1779. {
  1780.     GRArc(MAP_OBJ_TO_WNDW_X(x), MAP_OBJ_TO_WNDW_Y(y), StAngle, EndAngle,
  1781.                       (int) (DrawingWindow -> BBox._Dx * r));
  1782. }
  1783.  
  1784. /******************************************************************************
  1785. * Text in window space.                                  *
  1786. ******************************************************************************/
  1787. void IntrWndwIText(int x, int y, char *s)
  1788. {
  1789.     GRText(x, y, s);
  1790. }
  1791.  
  1792. /******************************************************************************
  1793. * Text in object space.                                  *
  1794. ******************************************************************************/
  1795. void IntrWndwRText(IntrRType x, IntrRType y, char *s)
  1796. {
  1797.     GRSText(MAP_OBJ_TO_WNDW_X(x), MAP_OBJ_TO_WNDW_Y(y), s);
  1798. }
  1799.